package com.quanshu.shop.pay.view;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.quanshu.exchange.R;
import com.quanshu.exchange.support.utils.RxViewHelper;
import com.quanshu.exchange.ui.base.BaseActivity;
import com.quanshu.exchange.ui.gui.profile.AllOrderActivity;
import com.quanshu.shop.base.tool.BaseTool;
import com.quanshu.shop.base.view.BaseTitleBar;
import com.quanshu.shop.order.SubmitOrderActivity;
import com.quanshu.shop.order.entity.CreatOrderEntity;
import com.quanshu.shop.pay.PayCashActivity;
import com.quanshu.shop.pay.PayNjfActivity;

import butterknife.BindView;
import butterknife.ButterKnife;

public class NjfPayResultActivity extends BaseActivity {

    @BindView(R.id.pay_result_title)
    BaseTitleBar payResultTitle;
    @BindView(R.id.pay_result_tips)
    TextView payResultTips;
    @BindView(R.id.pay_result_tips1)
    TextView payResultTips1;
    @BindView(R.id.pay_result_fl_tips)
    FrameLayout payResultFlTips;
    @BindView(R.id.pay_result_cash)
    TextView payResultCash;
    @BindView(R.id.pay_result_no_cash)
    TextView payResultNoCash;
    @BindView(R.id.pay_result_finish)
    TextView payResultFinish;
    @BindView(R.id.pay_result_to_cash)
    LinearLayout payResultToCash;
    private Bundle bundle;
    private Context context;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_njf_pay_result);
        ButterKnife.bind(this);
        context = this;
        initView();
    }

    private void initView() {
        payResultTitle.setCenterText("牛积分订单支付结果");
        bundle = getIntent().getExtras();
        if (bundle != null) {
            String payResult = bundle.getString(PayNjfActivity.NJF_PAY_STATE);
            CreatOrderEntity creatOrderEntity = (CreatOrderEntity) bundle.getSerializable(SubmitOrderActivity.CREATE_ORDER);
            if (payResult != null) {
                if (Integer.parseInt(payResult) == 1) {
                    //支付成功
                    payResultTips.setVisibility(View.VISIBLE);
                    payResultTips1.setVisibility(View.INVISIBLE);
                } else {
                    //支付失败
                    payResultTips1.setVisibility(View.VISIBLE);
                    payResultTips.setVisibility(View.INVISIBLE);
                }
            }
            if (creatOrderEntity != null) {
                if (TextUtils.isEmpty(creatOrderEntity.getAliString()) && TextUtils.isEmpty(creatOrderEntity.getWxString())) {
                    payResultToCash.setVisibility(View.INVISIBLE);
                    payResultFinish.setVisibility(View.VISIBLE);
                } else {
                    payResultToCash.setVisibility(View.VISIBLE);
                    payResultFinish.setVisibility(View.INVISIBLE);
                }
            }

        }
        RxViewHelper.getInstance().clicks(payResultCash, aVoid ->
                {
                    //去支付现金订单
                    BaseTool.goActivity(context, PayCashActivity.class, bundle);
                    finish();

                }

        );
        RxViewHelper.getInstance().clicks(payResultNoCash, aVoid ->
                {
                    //不去支付现金订单,跳转到订单列表
                    Intent intent = new Intent(this, AllOrderActivity.class);
                    intent.putExtra("ORDER_FLAG", 1);
                    startActivity(intent);
                    finish();

                }

        );
        RxViewHelper.getInstance().clicks(payResultFinish, aVoid ->
                {
                    //没有现金订单，直接跳转到订单列表
                    Intent intent = new Intent(this, AllOrderActivity.class);
                    intent.putExtra("ORDER_FLAG", 1);
                    startActivity(intent);
                    finish();
                }

        );

    }
}
